<div class="form">


<?php $form = $this->beginWidget('GxActiveForm', array(
	'id' => 'firm-additional-category-form',
	'enableAjaxValidation' => false,
));
?>

	<p class="note">
		<?php echo AdminModule::t('Поля помеченные '); ?> <span class="required">*</span> <?php echo AdminModule::t('являются обязательными'); ?>.
	</p>

	<?php echo $form->errorSummary($model); ?>
		<div class="row">
		<?php echo $form->labelEx($model,'user_id'); ?>
		<?php
            echo $form->dropDownList($model, 'user_id', GxHtml::listDataEx(Users::model()->visible()->findAllAttributes(null, true, 'usergroup_id NOT IN (4)')),
            array(
                'ajax' => array(
                    'type'=>'POST', //request type
                    'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                    'update'=>'#dropdown_firms',
                    'data'=>array('user_id'=>'js:this.value', 'pkey'=>'user_id', 'model'=>'Firms', 'ovkey'=>'id', 'olkey' => 'title', /*'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')*/),
                )
            ));
		?>
		<?php echo $form->error($model,'user_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'firm_id'); ?>
		<?php
			$user_id = 0 < $model->user_id ? $model->user_id : 1;
			$list_data = GxHtml::listDataEx(Firms::model()->visible()->findAllAttributes(null, true, 'user_id = :uid', array(':uid' => $user_id)));
			if (0 >= count($list_data)) {
				$list_data = array(0 => AdminModule::t('Не найдено фирм для выбранного пользователя'));
			}			
			echo $form->dropDownList($model, 'firm_id', 
				$list_data, 
				array('id'=>'dropdown_firms')
			);         
		?>
		<?php echo $form->error($model,'firm_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'service_type'); ?>
		<?php  
            echo $form->dropDownList($model, 'service_type', Controller::getServiceTypes(),
            array(
                'ajax' => array(
                    'type'=>'POST', //request type
                    'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                    'update'=>'#dropdown_rubrics',
                    'data'=>array('service_type'=>'js:this.value', 'pkey'=>'service_type', 'model'=>'Rubrics', 'ovkey'=>'id', 'olkey' => 'name', /*'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')*/),
                    'success' => 'function(html) {
                            jQuery("#dropdown_rubrics").html(html);
                            jQuery("#dropdown_rubrics").change();
                    }'                      
                )
            ));
        ?>
		<?php echo $form->error($model,'service_type'); ?>
		</div><!-- row -->        
        
        
        
		<div class="row">
        <?php $service_type = (null != $model->service_type) ? $model->service_type : 0; ?>
		<?php echo $form->labelEx($model,'rubric_id'); ?>
		<?php echo $form->dropDownList($model, 'rubric_id', GxHtml::listDataEx(Rubrics::model()->visible()->servicetype($service_type)->findAllAttributes(null, true)),
            array(
                'id'=>'dropdown_rubrics',
                'ajax' => array(
                    'type'=>'POST', //request type
                    'url'=> $this->createUrl('/admin/default/modelkeyoptions'),
                    'data'=>array('rubric_id'=>'js:this.value', 'pkey'=>'rubric_id', 'model'=>'Categories', 'ovkey'=>'id', 'olkey' => 'name', /*'dvkey'=> '', 'dlkey'=>AdminModule::t('Все')*/),
					'update'=>'#dropdown_categories',
                )
            )
		); ?>
		<?php echo $form->error($model,'rubric_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'category_id'); ?>
		<?php 
			$rubric_id = 0 < $model->rubric_id ? $model->rubric_id : Yii::app()->params['default_rubric_id'];
			echo $form->dropDownList($model, 'category_id', 
				GxHtml::listDataEx(Categories::model()->visible()->rubric_id($rubric_id)->servicetype($service_type)->findAllAttributes(null, true)), 
				array('id'=>'dropdown_categories')
			);
		?>
		<?php echo $form->error($model,'category_id'); ?>
		</div><!-- row -->



<?php
echo GxHtml::submitButton(AdminModule::t('Сохранить'));
$this->endWidget();
?>
</div><!-- form -->